//
//  Dates.swift
//  JXBaseTools
//
//  Created by godox on 2022/2/17.
//

import Foundation


extension Date {

    /// 获取当前 秒级 时间戳 - 10位
    public var timeStamp : Int {
        let timeInterval: TimeInterval = self.timeIntervalSince1970
        let timeStamp = Int(timeInterval)
        return timeStamp
    }

    /// 获取当前 毫秒级 时间戳 - 13位
    public var milliStamp : Int {
        let timeInterval: TimeInterval = self.timeIntervalSince1970
        let millisecond = CLongLong(round(timeInterval*1000))
        return Int(millisecond)
    }
    
    public static var nowTime: String {
        
        let date = Date()
        let timeFormatter = DateFormatter()
        timeFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return timeFormatter.string(from: date) as String
    }
    
    public static var nowDayTime: String {
        
        let date = Date()
        let timeFormatter = DateFormatter()
        timeFormatter.dateFormat = "yyyy-MM-dd"
        return timeFormatter.string(from: date) as String
    }
    
    public static var onlyTime: String {
        
        let date = Date()
        let timeFormatter = DateFormatter()
        timeFormatter.dateFormat = "HH:mm:ss"
        return timeFormatter.string(from: date) as String
    }
    
}
